---
schema_version: "1"
id: 6bd40550a8097b255231986a91ca4ba1427f65b8327763468be1eddabb8bb009
title: Get Started with AMPscript Development—Lesson 1
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/guide/get-started/mc-ampscript-get-started-learning-lesson-1.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/guide/mc-ampscript-get-started-learning-lesson-1.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5e690d503ce56ed7d6ebcaefd7b99f13702e8923b8414dc15fb010599ef62b66
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# Get Started with AMPscript Development—Lesson 1

This lesson introduces you to the basics of using AMPscript in your messages.

- Creating variables
- Using variables to refer to values in a data extension
- Displaying the value of a variable in a message

Northern Trail Outfitters (NTO), the fictitious company that we refer to in this lesson, has a sendable data extension that contains several pieces of information about their subscribers.

| Data Extension Column Name | Description                                                                              |
| -------------------------- | ---------------------------------------------------------------------------------------- |
| `MemberID`                 | A unique member ID number for the subscriber                                             |
| `FirstName`                | The subscriber’s first or given name                                                     |
| `LastName`                 | The subscriber’s surname or family name                                                  |
| `PrefName`                 | The subscriber’s preferred name                                                          |
| `Address`                  | The subscriber’s street address                                                          |
| `City`                     | The city that the subscriber lives in                                                    |
| `State`                    | The state, province, or other subnational unit where the subscriber lives                |
| `PostalCode`               | The subscriber’s postal code                                                             |
| `MemPref`                  | The subscriber’s preferred outdoor activity                                              |
| `Plat`                     | A true or false value that indicates whether the subscriber is a platinum rewards member |

## Message Content

This code example contains the message content for this lesson.

```
%%[
  Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
  Set @memid = MemberID
  Set @fname = FirstName
  Set @lname = LastName
  Set @prefname = PrefName
  Set @address = Address
  Set @postcode = PostalCode
  Set @mempref = MemPref
  Set @plat = Plat
]%%

Hello %%= v(@fname) =%%! Here are your account details.
First Name: %%= v(@fname) =%%
Last Name:%%= v(@lname) =%%
Preferred Name: %%= v(@prefname) =%%
Address Address: %%= v(@address) =%%
Postal Code: %%= v(@zip) =%%
Member Preferences Shopping Preference: %%= v(@mempref) =%%
Platinum Member: %%= v(@plat) =%%
```

If you’re new to AMPscript, it’s helpful to move through the AMPscript sample code line by line so that you can better understand how AMPscript works.

## AMPscript Block Opening Tag

The example begins with `%%[`, which indicates the beginning of a block of AMPscript code.

## Variable Declaration

The second line of the example begins with `Var`, followed by several names that begin with `@`. Each of these names is used as a variable later in the code example. The `@` sign is required at the beginning of each AMPscript variable. At this point, all of the variables have been declared, but the value for each one is `null`.

```
  Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
```

## Variable Assignments

The next several lines begin with `Set`, followed by the name of one of the declared variables. These lines assign a value to each of the declared variables. The value of each variable is set to equal the corresponding column in the sendable data extension that this email targets. When the email is sent, the system retrieves the value in the specified column for each subscriber and assigns that value to the variable.

```
  Set @memid = MemberID
  Set @fname = FirstName
  Set @lname = LastName
  Set @prefname = PrefName
  Set @address = Address
  Set @postcode = PostalCode
  Set @mempref = MemPref
  Set @plat = Plat
```

## AMPscript Block Closing Tag

After the variable assignments is the string `]%%`. This string indicates the end of a block of AMPscript code.

## Message Text

After the initial AMPscript block is closed, we see the first line of the message body. This line is the first that produces content that’s visible to the subscriber.

This line contains the text `%%= v(@fname) =%%`. The `%%=` indicates the beginning of a string of inline AMPscript code, and the `=%%` indicates the end. Between these tags is the function `v(@fname)`. The [v() function](/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-utilities/mc-ampscript-reference-utilities-v.html) is a utility function that outputs the value of a variable. The function refers to the `@fname` variable.

```
Hello %%= v(@fname) =%%! Here are your account details.
```

When a subscriber receives an email that contains this code, their name appears in the text instead of the AMPscript code.

## Send a Test Email

If you’re new to Marketing Cloud Engagement, see [Get Started with Email Studio](https://help.salesforce.com/s/articleView?id=mktg.mc_es_get_started_checklist_for_email_studio.htm) to learn more about creating an email.

This lesson assumes that you’re familiar with creating an email and that you already set up Marketing Cloud Engagement to send emails.

1. In the Email Studio editor, paste the sample AMPscript into a content area.

![A sample message in the Email Studio content editor. The sample AMPscript code from this lesson is pasted into a content area in the message.](https://developer.salesforce.com/media/images/ampscript/mc-ampscript-guide-get-started-learning-lesson1-1.png)

1. When you finish editing the message content, click **Next**.
2. On the **Preview and Test** page, click the **Subscriber Preview** tab.
3. Click the folder icon.
4. Expand the **Data Extensions** folder, and then select a data extension that contains the data for your target subscribers.
5. Select a subscriber. When you send the email, that subscriber’s information is populated in the message body.

![The Subscriber Preview tab on the Preview and Send page. A folder structure on the left side shows an expanded folder labeled Data Extensions. Under that folder, a data extension called NTO Customer List is selected. A list of subscribers is shown on the right side of the page, and the third row of data is selected.](https://developer.salesforce.com/media/images/ampscript/mc-ampscript-guide-get-started-learning-lesson1-2.png)

7. On the Test Send tab, choose whether to send the test message to **Individuals** or to a **Test data extension**. If you choose to send to individuals, enter their email addresses. If you choose to send to a data extension, choose a testable data extension.
8. Click **Send Test**.
9. Review the test message. In the test message, the inline AMPscript code in the message body is replaced with subscriber data from the row you selected in the data extension.

![An image of the test email. The fields in the message, such as First Name and Last Name, are populated with values from the selected data extension.](https://developer.salesforce.com/media/images/ampscript/mc-ampscript-guide-get-started-learning-lesson1-3.png)
