BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
joseph626
Obsidian | Level 7

Hi there,

 

I have a wide form of longitudinal dataset recording scores of multiple times like this

 

ID Group   Time0 Time1 Time4 Time9 Time15 Time24 Time37 (...)

 

1  A           10        15        17        9          8            29         9

2  A            21       39        32        .           33          31         23

(...)

 

and I'm using array to convert this dataset to convert this dataset to the long form, like that

 

ID Group Time Score

1   A         0       10

1   A         1        15

(...)

 

Since there are lots of Timepoints in the wide data, and the numbers are irregular, I have to write a ton of "if...else" following the array, just to change values of variable "Time" in the new dataset. 

I wonder if Is there any way to just extract the number following the variable Time0 Time4... and put it as the value in the new Time variable?

 

Thanks so much!

 

Joe

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use VNAME to get the variable name in an array. 

Use COMPRESS to retain only digits. 

Use INPUT to convert to a number. 

View solution in original post

2 REPLIES 2
Reeza
Super User

Use VNAME to get the variable name in an array. 

Use COMPRESS to retain only digits. 

Use INPUT to convert to a number. 

joseph626
Obsidian | Level 7

Thanks Reeza!

 

I did the following code and it get the jobs done!

 

	time = input(compress(vname(array[i]),,'kd'), 6.);

 

 

 

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1483 views
  • 2 likes
  • 2 in conversation